package JDBC;

import java.io.File;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import SwingModel.CmsLecture;

public class StudentLectureActivities {

	public static List<CmsLecture> getListOfLecture(String courseID){
		List<CmsLecture> listOfLecture = new ArrayList();
		try{
			//Database Connection and Retrieve data
			CmsDatabaseConnection dCon = new CmsDatabaseConnection();
			PreparedStatement pstmt = dCon.getPreparedStatement();
			pstmt = dCon.connection.prepareStatement("select * from dbcms.Lect_Files where courseID=? AND availDTM < CURRENT_TIMESTAMP AND expDTM > CURRENT_TIMESTAMP order by availDTM desc");
			pstmt.setString(1,courseID);
			ResultSet resultSet = pstmt.executeQuery();

			
			for(int i = 0; resultSet.next(); i++){
				CmsLecture lecture;
				int lectureID;
				File lectFile;
				Date avaiDate;
				Date expDate;
				
				//get first name, last name, username:
				lectureID = resultSet.getInt("LectFileID");
				lectFile = new File(resultSet.getString("LectFilePath"));
				avaiDate = new Date(resultSet.getTimestamp("availDTM").getTime());
				expDate = new Date(resultSet.getTimestamp("expDTM").getTime());
				
				//add people entry to list of people
				lecture = new CmsLecture(lectureID,courseID,lectFile,avaiDate,expDate);
				listOfLecture.add(lecture);
			}
		} catch(Exception e){}
		
		return listOfLecture;
	}
}
